﻿if (typeof Axis == "undefined") Axis = {};
if (typeof Axis.View == "undefined") Axis.View = {};
if (typeof Axis.View.News == "undefined") Axis.View.News = {};

Axis.View.News.List = {
    Init: function () {
        this.Paging.Init();
    },
    Paging: {
        isFirstPaging: true,
        Init: function () {
            var thisObj = this;
            thisObj.GetData(1, true);
        },
        GetData: function (pPageNumber, bmn) {
            var objThis = this;
            var catID = $.GetURL("ID") || "";
            if (catID == "")
                if (typeof CateID != 'undefined')
                    catID = CateID;
            var rPerPage = 5;
            if (typeof RowPerPage != 'undefined')
                rPerPage = RowPerPage;

            var data = '{' + $.string.Format('"page":{0},"rows":{1},"catID":"{2}"', pPageNumber, rPerPage, catID) + '}';
            var url = '/Views/News/Service/NewsService.asmx/GetListNews';

            if (typeof isPageHome != "undefined" && isPageHome) {
                // biến global khai báo ở trang home/default.aspx
                data = '{' + $.string.Format('"page":{0},"rows":{1}', pPageNumber, rPerPage) + '}';
                url = '/Views/News/Service/NewsService.asmx/GetNewListByHome';
            }
            $.Ajax({
                type: "POST",
                url: url,
                cache: false,
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                data: data,
                success: function (pData) {
                    var data = eval("(" + pData.d + ")");
                    Axis.View.News.List.ShowNewsList(data);
                    if (data.records == undefined)
                        data.records = rPerPage;
                   // console.log(data, 'data.total', data.total, 'data.records', data.records);
                    if (bmn) {
                        $("#paging").jpaging({
                            all_items_num: data.total,
                            items_on_page: data.records,
                            callback: function (a, b, c) {
                                objThis.GetData(a);
                            }
                        });
                    }

                }
            });
        }
    },

    ShowNewsList: function (data) {
        var htmlContent = "";
        var pattern = "<li>"
            + "<div class='newsImage'>&nbsp;<img class='imgNews' src='{0}' /></div>"
            + "<div class='newsPanel'>"
                + "<div>"
                    + "<h1 class='SEOH1'> <a href='../News/{4}#{5}' class='newsTitle'>{1}</a></h1>"
                + "</div>"
                + "<div class='newsDateTime'>(Cập nhật {2})</div>"
                + "<div class='newsDescription'>{3}....</div>"
                + "<div><a href='../News/{4}#{5}' class='newsMore'>Chi tiết</a></div>"
            + "</div>"
        + "</li>";
        $.each(data.list, function (index, Item) {
            var _date = $.CFormat.FormatDateSerializer(Item.WritenDate);
            htmlContent += $.string.Format(pattern, Item.Image, Item.Title, _date, Item.Summary, Item.ID, $.ReplacePoint(Item.Title));
        });
        $(".news_list_content").html(htmlContent);
    }
};
$(function () {
    Axis.View.News.List.Init();
});
function ShowDetail(id,cateID) {
    window.location.assign( $.string.Format("../News/{0}" ,id,cateID));
}